﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Administracion;
using Generico.Coneccion;
namespace CienciaYDeporte.Administracion
{
    public partial class Formulario_web15 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var _FileBrowser = new CKFinder.FileBrowser {BasePath = "../ckfinder/"};
            _FileBrowser.SetupCKEditor(this.txtImagen);

            if (!this.IsPostBack)
            {
                var cn = new ClsConeccion();
                cn.Abrir();
                var rd = cn.EjecutarSpDataReader("spImagenes");
                var dt = new DataTable();
                dt.Load(rd);
                this.drop.DataSource = dt;
                this.drop.DataTextField = "nombre";
                this.drop.DataValueField = "id";
                this.drop.DataBind();
                this.drop.SelectedIndex = 0;


                var cn1 = new ClsConeccion();
                cn1.Abrir();
                cn1.AgregarParametros("idImagen", Convert.ToInt32(drop.SelectedValue));
                var rd1 = cn1.EjecutarSpDataReader("spGetImagen");
                while (rd1.Read())
                {
                    txtImagen.Text = Convert.IsDBNull(rd1["link"]) ? "" : (string)rd1["link"];
                    lblAlto.Text += " " + (Convert.IsDBNull(rd1["Alto"]) ? "" : (string)rd1["Alto"]);
                    lblAncho.Text += " " + (Convert.IsDBNull(rd1["Ancho"]) ? "" : (string)rd1["Ancho"]);
                }
                rd1.Close();
                cn1.Cerrar();
                cn.Cerrar();
            }
        }

        protected void drop_SelectedIndexChanged(object sender, EventArgs e)
        {
            var cn1 = new ClsConeccion();
            cn1.Abrir();
            cn1.AgregarParametros("idImagen", Convert.ToInt32(drop.SelectedValue));
            var rd1 = cn1.EjecutarSpDataReader("spGetImagen");
            while (rd1.Read())
            {
                txtImagen.Text = Convert.IsDBNull(rd1["link"]) ? "" : (string)rd1["link"];
                lblAlto.Text = "Alto " + (Convert.IsDBNull(rd1["Alto"]) ? "" : (string)rd1["Alto"]);
                lblAncho.Text = "Ancho " + (Convert.IsDBNull(rd1["Ancho"]) ? "" : (string)rd1["Ancho"]);
            }
            rd1.Close();
            cn1.Cerrar();
        }

        protected void btnGuardar_Click(object sender, EventArgs e)
        {
            var cn1 = new ClsConeccion();
            cn1.Abrir();
            string link = txtImagen.Text;
            link = link.Replace("<p>", "");
            link = link.Replace("</p>", "");
            cn1.AgregarParametros("idImagen", Convert.ToInt32(drop.SelectedValue));
            cn1.AgregarParametros("link", link);
            var rd1 = cn1.EjecutarSp("spUpdateImagen");
            cn1.Cerrar();
        }
    }
}
